/**
 * Created by Administrator on 2017/7/22.
 * 干瞪眼通用规则算法
 * author: DengZhan
 */



// 提供给外部的访问接口
/**
 * 说明
 * GanDengYan.checkCards
 * 作用:检测当前传入的牌是否符合当前规则
 * 参数是牌值数组，如[401,101,202,305]
 */

/**
 * 说明
 * GanDengYan.checkCardsWithOtherCards
 * 作用:根据指定的牌检测当前传入的牌是否符合当前规则，并且比指定牌更大
 * 第一个参数是牌值数组，如[401,101,202,305]
 * 第二个参数是标准格式的牌的对象数组
 * 数组的单个元素是以下形式的对象
 * obj = {
 *     originValue  : 402       //原始值
 *     replaceValue : 402       //替换值
 *     compareValue : 32        //比牌值
 *     id           : 2         //不算花色的值
 *     color        : 4         //花色
 *     isLaizi      : false     //是否是癞子牌
 * }
 */


module.exports = {

    maxHandCardsNum: null,              //最大手牌数量
    minCard: null,                      //最小的单牌
    maxCard: null,                      //最大的单牌
    minCardForStraight: null,           //可以组成顺子的最小的牌
    maxCardForStraight: null,           //可以组成顺子的最大的牌
    laiziCards: null,                   //癞子牌
    laiziMaxNum: null,                  //癞子牌最大数量
    cardsTotalNum: null,                //扑克牌的总数
    minCardsNumWithStraight: null,      //顺子起连的最小牌数
    minStrPairNum: null,                //连对要求的最小对子数量
    minZhaDan: null,                    //最小的炸弹类型
    initFlag: false,                    //是否已初始化的标志

    //牌值比较时的大小，不算花色
    cardValue: {
        "AdPoker": 0,
        "BigPoker": 34,
        "SmallPoker": 33,
        "2": 32,
        "A": 14,
        "1": 14,
        "K": 13,
        "13": 13,
        "Q": 12,
        "12": 12,
        "J": 11,
        "11": 11,
        "10": 10,
        "9": 9,
        "8": 8,
        "7": 7,
        "6": 6,
        "5": 5,
        "4": 4,
        "3": 3
    },
    //牌的id，不算花色,根据服务器定义
    cardId: {
        "AdPoker": 1,
        "BigPoker": 3,
        "SmallPoker": 2,
        "2": 2,
        "A": 1,
        "1": 1,
        "K": 13,
        "13": 13,
        "Q": 12,
        "12": 12,
        "J": 11,
        "11": 11,
        "10": 10,
        "9": 9,
        "8": 8,
        "7": 7,
        "6": 6,
        "5": 5,
        "4": 4,
        "3": 3
    },
    //花色顺序    根据服务器的定义,红桃为1，黑桃为2，方块为3，梅花为4
    cardColor: {
        "HeiTao": 2,
        "HongTao": 1,
        "MeiHua": 4,
        "FangKuai": 3
    },
    //标准扑克花色顺序
    cardStandardColor: {
        "HeiTao": 1,
        "HongTao": 2,
        "MeiHua": 3,
        "FangKuai": 4
    },
    //牌型
    cardType: {
        NONE: 0,        //无效牌
        SINGLE: 1,       //单张
        PAIR: 2,         //对子
        STRAIGHT: 3,     //顺子
        STRPAIR: 4,      //连对
        THREEBOOM: 5,    //三张炸
        FOURBOOM: 6,     //四张炸
        TWOLZ: 7,        //双赖炸
        FIVEBOOM: 8,     //五张炸
        THREELZBOOM: 9,  //三赖炸
        SIXBOOM: 10      //六张炸
    },
    //设置牌对应的比牌值
    setCardValue: function (name, value) {
        if (name && value) {
            this.cardValue[name] = value;
        }

    },
    setCardId: function (name, id) {
        if (name && id) {
            this.cardId[name] = id;
        }
    },
    //设置最大的单牌
    setMaxCard: function (id) {
        if (id) {
            this.maxCard = this.cardValue[id];
        }
    },
    setMinCard: function (id) {
        if (id) {
            this.minCard = this.cardValue[id];
        }
    },
    setMaxCardForStraight: function (id) {
        if (id) {
            this.maxCardForStraight = this.cardValue[id];
        }
    },
    setMinCardForStraight: function (id) {
        if (id) {
            this.minCardForStraight = this.cardValue[id];
        }
    },
    // setCardsColor:function(color)
    // {
    //     if(undefined === color || null == color)
    //     {
    //         return;
    //     }
    //     if(Array.isArray(color) && 4 == color.length)
    //     {
    //         this.setHeiTaoColor(color[0]);
    //         this.setHongTaoColor(color[1]);
    //         this.setMeiHuaColor(color[2]);
    //         this.setFangKuaiColor(color[3]);
    //     }
    //     else
    //     {
    //         var functionArray = [this.setHeiTaoColor,this.setHongTaoColor,this.setMeiHuaColor,this.setFangKuaiColor];
    //         var suffix = 0;
    //         for(var property in color)
    //         {
    //             if(color.hasOwnProperty(property) && color[property])
    //             {
    //                 functionArray[suffix](color[property]);
    //                 suffix++;
    //                 if(suffix >= functionArray.length)
    //                 {
    //                     break;
    //                 }
    //             }
    //         }
    //     }
    // },
    setMinCardsNumWithStraight: function (num) {
        if (!isNaN(num)) {
            this.minCardsNumWithStraight = num;
        }
    },
    setLaiziCards: function (cards) {
        if (cards && Array.isArray(cards)) {
            this.laiziCards = [];
            for (var i = 0; i < cards.length; ++i) {
                this.laiziCards.push(cards[i]);
            }
        }
    },
    addLaiziCards: function (cards) {
        if (cards && Array.isArray(cards)) {
            for (var i = 0; i < cards.length; ++i) {
                this.laiziCards.push(cards[i]);
            }
        }
    },
    getLaiziMaxNum: function () {
        return this.laiziCards.length;
    },
    _transformColorToStandardColor: function (card) {
        var id = card % 100;
        var color = parseInt(card / 100);
        for (var index in this.cardColor) {
            if (this.cardColor.hasOwnProperty(index)) {
                if (color == this.cardColor(index)) {
                    color = this.cardStandardColor(index);
                }
            }
        }
        card = id + color * 100;
        return card;
    },
    transformColorToStandardColor: function (cards) {
        var array = [];
        if (cards && Array.isArray(cards)) {
            for (var i = 0; i < cards.length; ++i) {
                array.push(this._transformColorToStandardColor(cards[i]));
            }
        }
        return array;
    },

    setCardsTotalNum: function (num) {
        if (undefined == num || null == num) {
            return;
        }
        this.cardsTotalNum = num;
    },
    setRule: function (ruleName, functionName, callback, rValue) {
        if (undefined === ruleName || null == ruleName) {
            console.log("setRule failed, the para \"" + ruleName + "\" is incorrect");
            return;
        }
        if (undefined === functionName || null == functionName) {
            console.log("setRule failed, the para \"" + functionName + "\" is incorrect");
            return;
        }
        if (undefined === callback || null == callback) {
            console.log("setRule failed, the para \"" + callback + "\" is incorrect");
            return;
        }
        if (undefined === rValue || null == rValue) {
            console.log("setRule failed, the para \"" + rValue + "\" is incorrect");
            return;
        }
        var isModify = false;
        for (var index in this.rules) {
            if (this.rules.hasOwnProperty(index)) {
                var rules = this.rules[ruleName];
                for (var i = 0; i < rules.length; ++i) {
                    if (functionName == rules[i].cbName) {
                        rules[i].callback = callback;
                        rules[i].rValue = rValue;
                        isModify = true;
                    }
                }
            }
        }
        if (!isModify) {
            if (this.rules.hasOwnProperty(ruleName)) {
                var tmp = {};
                tmp.callback = callback;
                tmp.cbName = functionName;
                tmp.rValue = rValue;
                this.rules[ruleName].push(tmp);
            }
        }
    },
    addRule: function (ruleName, functionName, callback, rValue) {
        if (undefined === ruleName || null == ruleName) {
            console.log("addRule failed, the para \"" + ruleName + "\" is incorrect");
            return;
        }
        if (undefined === functionName || null == functionName) {
            console.log("addRule failed, the para \"" + functionName + "\" is incorrect");
            return;
        }
        if (undefined === callback || null == callback) {
            console.log("addRule failed, the para \"" + callback + "\" is incorrect");
            return;
        }
        if (undefined === rValue || null == rValue) {
            console.log("addRule failed, the para \"" + rValue + "\" is incorrect");
            return;
        }

        var tmp = {};
        tmp.callback = callback;
        tmp.cbName = functionName;
        tmp.rValue = rValue;
        if (undefined === this.rules[ruleName] || null == this.rules[ruleName]) {
            console.log("addRule to " + ruleName + " failed, this rule \"" + ruleName + "\" is not exist");
            console.log("At present,the ruleNames are :");
            for (var index in this.rules) {
                if (this.rules.hasOwnProperty(index)) {
                    console.log("rule name : " + index);
                }
            }
            return;
        }
        else {
            this.rules[ruleName].push(tmp);
        }

        console.log("addRule to " + ruleName + " with " + functionName + " is suconsoleessed");
    },
    removeRuleWithRuleName: function (ruleName) {
        if (this.rules.hasOwnProperty(ruleName)) {
            //this.rules[ruleName] = [];
            delete this.rules[ruleName];
        }
    },
    removeRuleWithFunctionName: function (functionName) {
        for (var index in this.rules) {
            if (this.rules.hasOwnProperty(index) && this.rules[index]) {
                var rules = this.rules[index];
                for (var i = 0; i < rules.length; ++i) {
                    if (functionName == rules[i].cbName) {
                        rules.splice(i, 1);
                    }
                }
            }
        }
    },
    resetRule: function () {
        for (var index in this.rules) {
            if (this.rules.hasOwnProperty(index) && this.rules[index]) {
                this.rules[index] = [];
            }
        }
    },
    initRule: function () {
        this.rules = {};
        this.rules["any"] = [];
        for (var i = 1; i <= this.maxHandCardsNum; ++i) {
            this.rules["" + i] = [];
        }
        this.addRule("any", "rule_lianDui", this.rule_lianDui.bind(this), this.cardType.STRPAIR);
        this.addRule("any", "rule_shunZi", this.rule_shunZi.bind(this), this.cardType.STRAIGHT);
        this.addRule("1", "rule_danPai", this.rule_danPai.bind(this), this.cardType.SINGLE);
        this.addRule("2", "rule_duiZi", this.rule_duiZi.bind(this), this.cardType.PAIR);
        this.addRule("2", "rule_shuangLaiZha", this.rule_shuangLaiZha.bind(this), this.cardType.TWOLZ);
        this.addRule("3", "rule_sanLaiZha", this.rule_sanLaiZha.bind(this), this.cardType.THREELZBOOM);
        this.addRule("3", "rule_sanZhangZha", this.rule_sanZhangZha.bind(this), this.cardType.THREEBOOM);
        this.addRule("4", "rule_siZhangZha", this.rule_siZhangZha.bind(this), this.cardType.FOURBOOM);
        this.addRule("5", "rule_wuZhangZha", this.rule_wuZhangZha.bind(this), this.cardType.FIVEBOOM);
        this.addRule("6", "rule_liuZhangZha", this.rule_liuZhangZha.bind(this), this.cardType.SIXBOOM);
    },
    addVerifyRule: function (ruleName, functionName, callback, rValue) {
        var tmp = {};
        tmp.callback = callback;
        tmp.cbName = functionName;
        tmp.rValue = rValue;
        if (undefined === this.verifyRules[ruleName] || null == this.verifyRules[ruleName]) {
            console.log("addVerifyRule to " + ruleName + " failed, this rule \"" + ruleName + "\" is not exist");
            console.log("At present,the ruleNames are :");
            for (var index in this.verifyRules) {
                if (this.verifyRules.hasOwnProperty(index)) {
                    console.log("rule name : " + index);
                }
            }
            return;
        }
        else {
            this.verifyRules[ruleName].push(tmp);
        }
        console.log("addVerifyRule to " + ruleName + " with " + functionName + " is suconsoleessed");
    },
    initVerifyRule: function () {
        this.verifyRules = {};
        this.verifyRules["any"] = [];
        for (var i = 1; i <= this.maxHandCardsNum; ++i) {
            this.verifyRules["" + i] = [];
        }
        this.addVerifyRule("any", "verify_shunZi", this.verify_shunZi.bind(this), this.cardType.STRAIGHT);
        this.addVerifyRule("any", "verify_lianDui", this.verify_lianDui.bind(this), this.cardType.STRPAIR);
        this.addVerifyRule("1", "verify_danPai", this.verify_danPai.bind(this), this.cardType.SINGLE);
        this.addVerifyRule("2", "verify_duiZi", this.verify_duiZi.bind(this), this.cardType.PAIR);
        this.addVerifyRule("2", "verify_shuangLaiZha", this.verify_shuangLaiZha.bind(this), this.cardType.TWOLZ);
        this.addVerifyRule("3", "verify_sanLaiZha", this.verify_sanLaiZha.bind(this), this.cardType.THREELZBOOM);
        this.addVerifyRule("3", "verify_sanZhangZha", this.verify_sanZhangZha.bind(this), this.cardType.THREEBOOM);
        this.addVerifyRule("4", "verify_siZhangZha", this.verify_siZhangZha.bind(this), this.cardType.FOURBOOM);
        this.addVerifyRule("5", "verify_wuZhangZha", this.verify_wuZhangZha.bind(this), this.cardType.FIVEBOOM);
        this.addVerifyRule("6", "verify_liuZhangZha", this.verify_liuZhangZha.bind(this), this.cardType.SIXBOOM);
    },
    init: function () {
        this.maxCard = this.cardValue["2"];
        this.minCard = this.cardValue["3"];
        this.minCardForStraight = this.cardValue["3"];
        this.maxCardForStraight = this.cardValue["A"];
        this.maxHandCardsNum = 6;
        this.minCardsNumWithStraight = 3;
        this.minStrPairNum = 2;
        this.minZhaDan = this.cardType.THREEBOOM;
        //this.cardsTotalNum = 55;
        this.laiziCards = [this.cardId["AdPoker"], this.cardId["SmallPoker"], this.cardId["BigPoker"]];
        this.result = null;
        this.tipResult = null;
        this.initRule();
        this.initVerifyRule();
        this.initFlag = true;
    },

    getCheckResult: function () {
        return this.result;
    },
    getStandardFormatCardsObj: function (cards) {
        return this._transformStandardCards(cards);
    },
    _transformStandardCards: function (cards) {
        var checkCards = {};
        checkCards.cards = [];
        checkCards.laiziNum = 0;    //癞子牌数量
        checkCards.cardsCount = cards.length;
        checkCards.cardNum = 0;     //普通牌数量
        checkCards.type = 0;        //牌型
        // checkCards.maxCardId = 0;
        // checkCards.maxCardCompareValue = 0;
        //checkCards.maxCard = null;
        var tmp = null;
        var i = 0;
        var k = 0;
        for (i = 0; i < cards.length; ++i) {
            tmp = {};
            tmp.isLaizi = false;
            tmp.originValue = cards[i];     //原始值
            tmp.replaceValue = tmp.originValue; //替换的值
            for (k = 0; k < this.laiziCards.length; ++k) {
                if (tmp.originValue == this.laiziCards[k]) {
                    tmp.isLaizi = true;
                    break;
                }
            }
            if (tmp.isLaizi) {
                tmp.id = 0;
                //tmp.compareValue = tmp.originValue;
                tmp.compareValue = 0;
                tmp.color = 0;
                checkCards.laiziNum++;
            }
            else {
                checkCards.cardNum++;
                tmp.id = tmp.originValue % 100;     //牌的id，除开花色的数字
                tmp.compareValue = this.cardValue["" + tmp.id];     //比牌的值
                tmp.color = parseInt(tmp.originValue / 100);   //花色
            }
            checkCards.cards.push(tmp);
        }
        //排序
        checkCards.cards.sort(
            function (a, b) {
                if (0 == a.compareValue - b.compareValue) {
                    return a.originValue - b.originValue;
                }
                return a.compareValue - b.compareValue;
            });

        // for(i = 0; i < checkCards.cards.length; ++i)
        // {
        //     //console.log("检测牌 = " + checkCards.cards[i].originValue);
        //     //console.log("检测牌的比牌值 = " + checkCards.cards[i].compareValue);
        //     //console.log("检测牌的花色 = " + checkCards.cards[i].color);
        // }

        return checkCards;
    },
    _copyCheckCards: function (checkCards) {
        var myCheckCards = {};
        myCheckCards.laiziNum = checkCards.laiziNum;
        myCheckCards.cardsCount = checkCards.cardsCount;
        myCheckCards.cardNum = checkCards.cardNum;
        myCheckCards.type = 0;        //牌型
        // myCheckCards.maxCardId = checkCards.maxCardId;
        // myCheckCards.maxCardCompareValue = checkCards.maxCardCompareValue;
        //myCheckCards.maxCard = checkCards.maxCard;
        myCheckCards.cards = [];

        var cards = checkCards.cards;

        var tmp = null;
        var i = 0;
        for (i = 0; i < cards.length; ++i) {
            tmp = {};
            tmp.originValue = cards[i].originValue;
            tmp.replaceValue = cards[i].replaceValue;
            tmp.isLaizi = cards[i].isLaizi;
            tmp.id = cards[i].id;
            tmp.compareValue = cards[i].compareValue;
            tmp.color = cards[i].color;
            myCheckCards.cards.push(tmp);
        }
        return myCheckCards;
    },
    _copyCardsValue: function () {
        var cardsValue = [];
        var tmp = null;
        var i = 0;
        for (i = 1; i <= 13; ++i) {
            var index = "" + i;
            if (this.cardValue.hasOwnProperty(index)) {
                if (this.minCardForStraight <= this.cardValue[index]
                    && this.cardValue[index] <= this.maxCardForStraight) {
                    tmp = {};
                    tmp.compareValue = this.cardValue[index];
                    tmp.originValue = (+index) + 100;   //注:该属性用于癞子做替换时取的值
                    tmp.num = 0;
                    cardsValue.push(tmp);
                }
            }
        }
        // for(i = 0; i < cardsValue.length; ++i)
        // {
        //     console.log("拷贝牌 = " + cardsValue[i].compareValue);
        //     console.log("拷贝牌数量 = " + cardsValue[i].num);
        // }
        cardsValue.sort(function (a, b) {
            return a.compareValue - b.compareValue;
        });
        return cardsValue;
    },

    _addResult: function (checkCards, result) {
        var cards = checkCards.cards;
        //var maxCard = this.cardValue[cards[0].replaceValue % 100];
        var card = 0;
        //checkCards.maxCard = cards[0];
        for (var i = 0; i < cards.length; ++i) {
            card = this.cardValue[cards[i].replaceValue % 100];
            if (cards[i].replaceValue != cards[i].originValue) {
                cards[i].compareValue = card;
            }
        }
        checkCards.cards.sort(function (a, b) { return a.compareValue - b.compareValue; });
        checkCards.maxCard = checkCards.cards[checkCards.cards.length - 1];
        if (result) {
            result.push(checkCards);
        }
        else {
            this.result.push(checkCards);
        }
    },
    //检测出牌是否符合规则
    _checkCards: function (standardFormatCards) {
        var doRuleCall = function (rules) {
            //console.log("当前牌数的规则数量 = " + rule.length);
            for (var i = 0; i < rules.length; ++i) {
                var ruleCall = rules[i].callback;
                //console.log("规则回调 = " + callback);
                var rValue = rules[i].rValue;
                var checkCards = this._copyCheckCards(standardFormatCards);
                ruleCall(checkCards, rValue);
            }
        }.bind(this);

        var cards = standardFormatCards.cards;
        var len = cards.length;
        //console.log("牌的张数 = " + cards.length);
        doRuleCall(this.rules["" + len]);
        var isNeedCheckAny = true;
        for (var i = 0; i < this.result.length; ++i) {
            if (this.cardType.TWOLZ == this.result[i].type || this.cardType.THREELZBOOM == this.result[i].type) {
                isNeedCheckAny = false;
                break;
            }
        }
        if (isNeedCheckAny) {
            doRuleCall(this.rules["any"]);
        }
        return this.result;
    },
    _checkIsInit: function () {
        if (!this.initFlag) {
            console.log("GanDengYan rules is need init,please invoke the function \"init()\"");
            return false;
        }
        return true;
    },
    checkCards: function (cards) {
        if (!this._checkIsInit()) {
            return;
        }
        if (cards.length > this.maxHandCardsNum) {
            console.log("需要检测的牌张数不对");
            return;
        }
        this.result = [];
        var standardFormatCards = this._transformStandardCards(cards);
        return this._checkCards(standardFormatCards);
    },
    _verifyType: function (verifiedCards) {
        var doRuleCall = function (rules) {
            for (var i = 0; i < rules.length; ++i) {
                var ruleCall = rules[i].callback;
                var rValue = rules[i].rValue;
                ruleCall(verifiedCards, rValue);
                if (0 != verifiedCards.type) {
                    return;
                }
            }
        };
        var ruleName = "" + verifiedCards.cardsCount;
        var type = 0;
        var rules = null;
        if (this.verifyRules.hasOwnProperty(ruleName) && this.verifyRules[ruleName]) {
            rules = this.verifyRules[ruleName];
            doRuleCall(rules);
        }
        if (0 == verifiedCards.type) {
            rules = this.verifyRules["any"];
            doRuleCall(rules);
        }
    },
    getTypeWithVerifiedCards: function (cards) {
        if (!Array.isArray(cards)) {
            console.log("cards is not array，can't calculate type");
            return;
        }
        var verifiedCards = {};
        verifiedCards.cards = cards;
        verifiedCards.cards.sort(function (a, b) { return a.compareValue - b.compareValue });
        verifiedCards.cardsCount = cards.length;
        verifiedCards.laiziNum = 0;
        verifiedCards.cardNum = 0;
        verifiedCards.type = 0;
        var i = 0;
        var k = 0;
        for (i = 0; i < verifiedCards.cards.length; ++i) {
            for (k = 0; k < this.laiziCards.length; ++k) {
                if (verifiedCards.cards[i].originValue == this.laiziCards[k]) {
                    verifiedCards.cards[i].isLaizi = true;
                    break;
                }
            }
            if (verifiedCards.cards[i].isLaizi) {
                verifiedCards.laiziNum++;
            }
            else {
                verifiedCards.cardNum++;
            }
        }
        this._verifyType(verifiedCards);
        verifiedCards.maxCard = verifiedCards.cards[verifiedCards.cards.length - 1];
        return verifiedCards;
    },
    //检测出牌是否比另一组牌更大
    _compareCards: function (myCards, otherCards) {
        console.log("function _compareCards myCards.type = " + myCards.type);
        console.log("function _compareCards otherCards.type = " + otherCards.type);
        if (myCards.type >= this.minZhaDan && myCards.type > otherCards.type) {
            return true;
        }
        else if (myCards.type == otherCards.type) {
            //顺子、连对比较
            if (myCards.type == this.cardType.STRAIGHT || myCards.type == this.cardType.STRPAIR) {
                if (myCards.cardsCount == otherCards.cardsCount &&
                    1 == myCards.maxCard.compareValue - otherCards.maxCard.compareValue) {
                    return true;
                }
            }
            //单牌、对子比较
            else if (myCards.type == this.cardType.SINGLE || myCards.type == this.cardType.PAIR) {
                if (myCards.maxCard.compareValue > otherCards.maxCard.compareValue) {
                    if (myCards.maxCard.compareValue == this.cardValue["2"]) {
                        return true;
                    }
                    if (myCards.maxCard.compareValue - otherCards.maxCard.compareValue == 1) {
                        return true;
                    }
                }
            }
            else if (myCards.maxCard.compareValue > otherCards.maxCard.compareValue) {
                return true;
            }
        }
        return false;
    },
    compareCards: function (myCards, otherCards) {
        return this._compareCards(myCards, otherCards);
    },
    checkCardsWithOtherCards: function (cards, otherCards) {
        if (!this._checkIsInit()) {
            return;
        }
        this.checkCards(cards);
        var compareResultArray = [];
        var compareResultFlag = false;
        for (var i = 0; i < this.result.length; ++i) {
            console.log(this.result[i].cards);
            compareResultFlag = this._compareCards(this.result[i], otherCards);
            if (compareResultFlag) {
                compareResultArray.push(this.result[i]);
            }
        }
        return compareResultArray;
    },
    _checkTip: function () {

    },
    _getAllOrderCombine: function (cards) {
        var combine = [];
        var count = cards.length;
        for (var num = 1; num <= count; ++num) {
            var k = 0;
            var array = null;
            if (num > 1) {
                for (k = 0; k < count - num + 1; ++k) {
                    for (var i = num - 1 + k; i < count; ++i) {
                        array = [];
                        for (var j = 0; j < num - 1; ++j) {
                            array.push(cards[k + j]);
                        }
                        array.push(cards[i]);
                        combine.push(array);
                        //test.push(array);
                    }
                }
            }
            else if (1 == num) {
                for (k = 0; k < count; ++k) {
                    array = [];
                    array.push(cards[k]);
                    combine.push(array);
                }
            }
        }
        return combine;
    },
    //检测提示牌
    checkTip: function (cards) {
        if (!this._checkIsInit()) {
            return;
        }
        var orderCombine = this._getAllOrderCombine(cards);
        console.log("checkTip组合数量 = " + orderCombine.length);
        this.tipResult = [];
        for (var i = 0; i < orderCombine.length; ++i) {
            //console.log(orderCombine[i]);
            this.checkCards(orderCombine[i]);
            for (var k = 0; k < this.result.length; ++k) {
                this.tipResult.push(this.result[k]);
            }
        }
        console.log("checkTip合法牌型数量 = " + this.tipResult.length);
        return this.tipResult;
    },
    //检测比目标牌更大的牌
    checkTipWithOtherCards: function (cards, otherCards) {
        if (!this._checkIsInit()) {
            return;
        }
        var orderCombine = this._getAllOrderCombine(cards);
        console.log("checkTipWithOtherCards组合数量 = " + orderCombine.length);
        this.tipResult = [];
        var i = 0;
        var k = 0;
        for (i = 0; i < orderCombine.length; ++i) {
            console.log(orderCombine[i]);
            this.checkCards(orderCombine[i]);
            for (k = 0; k < this.result.length; ++k) {
                this.tipResult.push(this.result[k]);
            }
        }
        var compareResult = [];

        for (i = 0; i < this.tipResult.length; ++i) {
            if (this._compareCards(this.tipResult[i], otherCards)) {
                compareResult.push(this.tipResult[i]);
            }
        }

        console.log("checkTipWithOtherCards合法牌型数量 = " + compareResult.length);

        return compareResult;
    }
};